package com.augurit.common.syslog.convert;

import java.util.ArrayList;
import java.util.List;

import com.augurit.common.entity.SysPropAuditLog;
import com.augurit.common.syslog.web.form.SysPropAuditLogForm;

public class SysPropAuditLogConverter {
	
	public static SysPropAuditLogForm convertVoToForm(SysPropAuditLog entity) {
		if(entity != null) {
			SysPropAuditLogForm form = new SysPropAuditLogForm();
			form.setId(entity.getId());
			form.setEntity(entity.getEntity());
			form.setEntityId(entity.getEntityId());
			form.setPropertyName(entity.getPropertyName());
			form.setOldValue(entity.getOldValue());
			form.setNewValue(entity.getNewValue());
			form.setUpdator(entity.getUpdator());
			form.setUpdateTime(entity.getUpdateTime());
			form.setMemo(entity.getMemo());
			
			form.setPropertyComment(entity.getPropertyComment() != null ? 
					entity.getPropertyComment() : entity.getPropertyName());
			
			return form;
		}else
			return null;
	}
	
	public static void convertFormToVo(SysPropAuditLogForm form, SysPropAuditLog entity) {
		if(entity != null && form != null) {
			entity.setId(form.getId());
			if(form.getEntity() != null && form.getEntity().trim().length() > 0)
				entity.setEntity(form.getEntity().trim());
			if(form.getEntityId() != null && form.getEntityId().trim().length() > 0)
				entity.setEntityId(form.getEntityId().trim());
			if(form.getPropertyName() != null && form.getPropertyName().trim().length() > 0)
				entity.setPropertyName(form.getPropertyName().trim());
			if(form.getOldValue() != null && form.getOldValue().trim().length() > 0)
				entity.setOldValue(form.getOldValue().trim());
			if(form.getNewValue() != null && form.getNewValue().trim().length() > 0)
				entity.setNewValue(form.getNewValue().trim());
			if(form.getUpdator() != null && form.getUpdator().trim().length() > 0)
				entity.setUpdator(form.getUpdator().trim());
			entity.setUpdateTime(form.getUpdateTime());
			if(form.getMemo() != null && form.getMemo().trim().length() > 0)
				entity.setMemo(form.getMemo().trim());
			if(form.getPropertyComment() != null && form.getPropertyComment().trim().length() > 0)
				entity.setPropertyComment(form.getPropertyComment().trim());
		}
	}
	
	public static List<SysPropAuditLogForm> convertVoListToFormList(List<SysPropAuditLog> sysLogPropAuditList) {
		if(sysLogPropAuditList != null && sysLogPropAuditList.size() > 0) {
			List<SysPropAuditLogForm> sysLogPropAuditFormList = new ArrayList();
			for(int i=0; i<sysLogPropAuditList.size(); i++) {
				SysPropAuditLogForm form = convertVoToForm(sysLogPropAuditList.get(i));
				sysLogPropAuditFormList.add(form);
			}
			return sysLogPropAuditFormList;
		}
		return null;
	}
	
	public static List<SysPropAuditLog> convertFormListToVoList(List<SysPropAuditLogForm> sysLogPropAuditFormList) {
		if(sysLogPropAuditFormList != null && sysLogPropAuditFormList.size() > 0) {
			List<SysPropAuditLog> sysLogPropAuditList = new ArrayList();
			for(int i=0; i<sysLogPropAuditFormList.size(); i++) {
				SysPropAuditLog sysLogPropAudit = new SysPropAuditLog();
				convertFormToVo(sysLogPropAuditFormList.get(i), sysLogPropAudit);
				sysLogPropAuditList.add(sysLogPropAudit);
			}
			return sysLogPropAuditList;
		}
		return null;
	}
}